import 'package:boss/provider/regist_provider.dart';
import 'package:boss/ui/widget/eye_icon.dart';
import 'package:boss/ui/widget/form/base_text_form_field.dart';
import 'package:boss/ui/widget/form/phone_code_form_field.dart';

import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

class RegistForm extends StatefulWidget {
  @override
  _RegistFormState createState() => _RegistFormState();
}

class _RegistFormState extends State<RegistForm> {
  bool passwordObscureText = true;
  bool checkPasswordObscureText = true;

  @override
  Widget build(BuildContext context) {
    var registProvider = Provider.of<RegistProvider>(context, listen: false);

    return Container(
      padding: EdgeInsets.symmetric(
        horizontal: 65.w,
      ),
      margin: EdgeInsets.only(
        top: ScreenUtil.instance.setHeight(45.5),
      ),
      child: Column(
        children: <Widget>[
          BaseTextFormField(
            hintText: '请输入你的手机号',
            textAlign: TextAlign.start,
            keyboardType: TextInputType.number,
            inputFormatters: [FilteringTextInputFormatter.allow(RegUtil.numberReg)],
            isClearAll: true,
            onChanged: (value) {
              registProvider.setPhone(value);
            },
          ),
          Consumer<RegistProvider>(
            builder: (context, registProvider, child) {
              return PhoneCodeFormField(
                codeType: CodeType.regist,
                phone: registProvider.phone,
                onChanged: (value) {
                  registProvider.setCode(value);
                },
              );
            },
          ),
          BaseTextFormField(
            hintText: '请输入6-16位含数字字母密码',
            textAlign: TextAlign.start,
            obscureText: passwordObscureText,
            onChanged: (value) {
              registProvider.setPassword(value);
            },
            suffix: EyeIcon(
              value: passwordObscureText,
              onTap: () {
                setState(() {
                  passwordObscureText = !passwordObscureText;
                });
              },
            ),
          ),
          BaseTextFormField(
            hintText: '请再次输入你的密码',
            textAlign: TextAlign.start,
            obscureText: checkPasswordObscureText,
            onChanged: (value) {
              registProvider.setConfirmPassword(value);
            },
            suffix: EyeIcon(
              value: checkPasswordObscureText,
              onTap: () {
                setState(() {
                  checkPasswordObscureText = !checkPasswordObscureText;
                });
              },
            ),
          ),
        ],
      ),
    );
  }
}
